//
//  MineViewController.swift
//  FlameB
//
//  Created by 连俊 on 2020/8/3.
//  Copyright © 2020 连俊. All rights reserved.
//

import UIKit

class MineViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func buildView() {
        let btn = UIButton(type: UIButton.ButtonType.custom)
        btn.setTitle("退出登录", for: UIControl.State.normal)
        btn.setTitleColor(UIColor.white, for: UIControl.State.normal)
        btn.backgroundColor = UIColor.brown
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 18)
        btn.layer.cornerRadius = 5
        btn.layer.masksToBounds = true
        view.addSubview(btn)
        btn.addTarget(self, action: #selector(settingAction), for: UIControl.Event.touchUpInside)
        btn.snp.makeConstraints { (make) in
            make.center.equalToSuperview()
            make.width.equalTo(150)
            make.height.equalTo(50)
        }
    }
    
    @objc func settingAction() {
        let alertView = UIAlertController()
        let action1 = UIAlertAction(title: "确定", style: UIAlertAction.Style.default, handler: { alert in
            _ = Keychain.clear()
            DBService.shared.openDB(with: "0000")
            guard let delegate = UIApplication.shared.delegate as? AppDelegate else{
               return
            }
            PageManager.shared.chooseRootViewController(delegate.window)
        })
        
        let action2 = UIAlertAction(title: "取消", style: UIAlertAction.Style.default, handler: { alert in
            
        })
        alertView.addAction(action1)
        alertView.addAction(action2)
        self.present(alertView, animated: true, completion: nil)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
